//
//  CWLabel.m
//  CWDevelop
//
//  Created by LittoCats on 7/22/14.
//  Copyright (c) 2014 Littocats. All rights reserved.
//

#import "CWLabel.h"
#import "CWBaseView.h"
#import "CWBaseLayout.h"

@implementation CWLabel

- (id)init
{
    self = [super init];
    self.numberOfLines = 0;
    return self;
}

- (CGSize)sizeThatFits:(CGSize)size
{
    CGSize defaultSize = [self.text sizeWithFont:self.font constrainedToSize:CGSizeMake(self.width, NSIntegerMax)];
    CGSize newSize;
    
    newSize.width = [self.attributes[@"width"] isEqualToString:@"wrap_content"] ? defaultSize.width : self.width;
    newSize.height = [self.attributes[@"height"] isEqualToString:@"wrap_content"] ? defaultSize.height : self.height;
    return newSize;
}


- (void)setText:(NSString *)text
{
    text ? [self.attributes setObject:text forKey:@"text"] : nil;
    [super setText:text];
    [self sizeToFit];
}
@end
